#include <stdio.h>
#include <string.h>

int n;
char map[15][15];
char out[15][15];

int check(int x, int y)
{
	if (x>=0 && y>=0 && x <n && y<n)
	{
		if (map[x][y] =='*') return 1;
	}
	return 0;
}

int main()
{
	int i, j, tot, x, y;
	bool touch;
	while (scanf("%d", &n)!=EOF)
	{
		memset(map, 0, sizeof(map));
		memset(out, 0, sizeof(out));
		for (i=0; i<n; ++i)
			scanf("%s", map[i]);
		for (i=0; i<n; ++i)
			scanf("%s", out[i]);
		touch = false;
		for (i=0; i<n; ++i)
			for (j=0; j<n; ++j)
			if (out[i][j] == 'x')
			{
				if (map[i][j] == '*') touch = true;
				tot = 0;
				x = i; y = j;
				tot += check(x+1, y);
				tot += check(x-1, y);
				tot += check(x, y+1);
				tot += check(x, y-1);
				tot += check(x+1, y+1);
				tot += check(x-1, y-1);
				tot += check(x+1, y-1);
				tot += check(x-1, y+1);
				out[i][j] = '0' + tot;
			}
		if (touch)
			for (i=0; i<n; ++i)
				for (j=0; j<n; ++j)
					if (map[i][j] == '*')
						out[i][j] = '*';
		for (i=0; i<n; ++i)
		{
			for (j=0; j<n; ++j)
				printf("%c", out[i][j]);
			printf("\n");
		}


	}


	return 0;
}
